package org.example.route.controller.AdminController;



import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jdk.jfr.Description;
import org.example.route.model.dto.BaseRequest;
import org.example.route.model.dto.CityDTO;
import org.example.route.model.dto.CityQueryDTO;
import org.example.route.model.pojo.Result;
import org.example.route.model.vo.CityVO;
import org.example.route.service.CityService;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/admin/city")
@Tag(name = "城市管理")
public class CityController {

    @Autowired
    private CityService cityService;





    @CacheEvict(cacheNames = "cityCache",allEntries = true)
    @Operation(summary = "添加城市")
    @PostMapping("/add")
    public Result add(@RequestBody CityDTO cityDTO)
    {
            cityService.add(cityDTO);
            return Result.success();
    }





    @Cacheable(cacheNames = "cityCache",key = "T(java.util.Objects).hash(#cityQueryDTO.name,#cityQueryDTO.provinceId)")
    @Operation(summary = "查询城市列表")
    @PostMapping("/list")

    public Result<List<CityVO>> list(@RequestBody CityQueryDTO cityQueryDTO)
    {

        List<CityVO> cityQueryDTOList = cityService.list(cityQueryDTO);
        return Result.success(cityQueryDTOList);
    }


    /**一测完成**/
    @CacheEvict(cacheNames = "cityCache",allEntries = true)
    @Operation(summary = "删除城市")
    @PostMapping("/delete")
    public Result delete(@RequestBody BaseRequest baseRequest)
    {
        cityService.delete(baseRequest);
        return Result.success();
    }

}
